Mobile development – a WiFi signal strength indicator

Here is one more windows mobile taskbar addon. I have seen many people are interested in these small widgets. This one shows the signal strength of the current associated access point in your taskbar.

The code is the same as with the other taskbaraddons you find here, only the code for wireless signal strength has been added. Oh, yes, and this addon uses small bitmaps to show the signal strength.

To get the signal strength I use part of PeekPocket code submission at CodeProject. I only need the name of the first wireless adapter.

CWifiPeek m_wp;
TCHAR* szAdapterName=new TCHAR[64];

ULONG GetCurrentValue(){
    WCHAR buf[1024];
    DWORD dwSize;
    dwSize=sizeof(buf);
    if(false == m_wp.GetAdapters(buf, dwSize) || dwSize == 0)
    {
        return UNKNOWERROR;
    }
    else{
        //we are only interested in first returned name
        wsprintf(szAdapterName, L"%s", buf);
        int iRSSI=0;
        int iRes = GetSignalStrength(szAdapterName, &iRSSI);
        if(iRes == ERROR_SUCCESS){
            return iRSSI;
        }
        else{
            return LOADLIBFAILED;
        }
    }
}

(http://www.codeproject.com/KB/windows/PeekPocket.aspx)

Then the signal strength is queried using another code snippet:

INT GetSignalStrength(TCHAR *ptcDeviceName, INT *piSignalStrength)
{
    PNDISUIO_QUERY_OID queryOID;
    DWORD dwBytesReturned = 0;
    UCHAR QueryBuffer[sizeof(NDISUIO_QUERY_OID)+sizeof(DWORD)];
    HANDLE ndisAccess = INVALID_HANDLE_VALUE;
    BOOL retval;
    INT hr;

    // Attach to NDISUIO.
    ndisAccess = CreateFile(NDISUIO_DEVICE_NAME, 0, 0, NULL,
    OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED,
    INVALID_HANDLE_VALUE );

    if (ndisAccess == INVALID_HANDLE_VALUE)
        return -1;

    // Get Signal strength
    queryOID = (PNDISUIO_QUERY_OID)&QueryBuffer[0];
    queryOID->ptcDeviceName = ptcDeviceName;
    queryOID->Oid = OID_802_11_RSSI;

    retval = DeviceIoControl(ndisAccess,
    IOCTL_NDISUIO_QUERY_OID_VALUE, (LPVOID)queryOID,
    sizeof(NDISUIO_QUERY_OID) + sizeof(DWORD), (LPVOID)queryOID,
    sizeof(NDISUIO_QUERY_OID) + sizeof(DWORD), &dwBytesReturned, NULL);

    if (retval && piSignalStrength)
    {
        hr = 0;
        *piSignalStrength = *(DWORD *)&queryOID->Data;
    }
    else
    {
        hr = -2;
    }

    CloseHandle(ndisAccess);

    return(hr);
}

(http://www.pcreview.co.uk/forums/thread-1306359.php)

Downloads

[Download not found] TaskbarAddon5 (2416 downloads )